﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->treeWidget->setHeaderLabels(QStringList() << QStringLiteral("姓名") << QStringLiteral("年龄"));
    //设置表头文字居中
    ui->treeWidget->header()->setDefaultAlignment(Qt::AlignCenter);

    QTreeWidgetItem *item0 = new QTreeWidgetItem(QStringList() << QStringLiteral("小明") << QStringLiteral("18"));
    QTreeWidgetItem *item1 = new QTreeWidgetItem(QStringList() << QStringLiteral("杰哥") << QStringLiteral("19"));

    //去除掉顶层节点下的子节点的rect不能铺满的情况
    ui->treeWidget->setRootIsDecorated(false);

    ui->treeWidget->addTopLevelItem(item0);
    ui->treeWidget->addTopLevelItem(item1);
}

MainWindow::~MainWindow()
{
    delete ui;
}
